<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>login</title>
    <link rel="stylesheet" type="text/css" href="../css/bootstrap/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="../css/town/base.css">
</head>
<body>
<div class="main-body">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12 title">TOWN图床</div>
        </div>
        <div class="row">
            <div class="col-lg-12">
    <form action="#" id="auth" method="POST">
            <input type="hidden" v-model="auth.csrf_token">
        <div class="form-group">
            <label for="inputName">用户名</label>
            <input type="text" class="form-control" placeholder="用户名" v-model.trim="auth.name">
        </div>
        <div class="form-group">
            <label for="inputpass">通行证</label>
            <input type="password" class="form-control" placeholder="通行证" v-model.trim="auth.pass">
        </div>
        <div class="form-group">
            <input type="checkbox" id="rememberMe" v-model="auth.remember">
            <label for="rememberMe">记住我</label>
        </div>
        <div class="form-group">
            <button type="button" class="btn btn-primary" v-on:click="clickLogin">登陆</button>
            <label>{{ auth.message }}</label>
        </div>
    </form>
            </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../js/vue.min.js"></script>
<script type="text/javascript" src="../js/login.js"></script>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
    var auth = new Vue({
        el: '#auth',
        data: {
            auth: {
                name: '',
                pass: '',
                message: '',
                remember: '',
                csrf_token: '{=$csrf_token}'
            }
        },
        methods: {
            clickLogin : function(data) {
                var url   = '/login';
                var json  = this.auth;
                var _self = this;
                $.post(url, json, function(res){
                    if (res.code == 0) {
                        window.location.href = '/';
                    } else {
                        _self.auth.message = res.msg;
                        _self.auth.csrf_token = res.csrf_token;
                    }
                }, 'json');
            }
        }
    });

</script>
</html>